class code1 {
    //1.颜色分类
    //注意：形参和实参的区别
    public void sortColors(int[] nums) {
        //left:0的右边界
        //right:1的右边界，2的左边界
        int left=-1,right=nums.length,i=0;
        while(i<right) {
            if(nums[i]==0) {
                swap(nums,++left,i++);
            }else if(nums[i]==1){
                i++;
            } else {
                swap(nums,i,--right);
            }
        }
    }
    public void swap(int[] nums,int a,int b) {
        int tmp = nums[a];
        nums[a] = nums[b];
        nums[b] = tmp;
    }
}